﻿ 
 var hdnReplaceTextString = $("#hdnReplace").val();
 var hdnBundleADSLHomeString = $("#hdnBundleADSLHome").val();
 var hdnBundleADSLVOIPString = $("#hdnBundleADSLVOIP").val();
 var hdnBundleADSLPhoneVOIPString = $("#hdnBundleADSLPhoneVOIP").val();

 var hdnNakedString = $("#hdnNaked").val();
 var hdnBundleString = $("#hdnBundle").val();
 var getFinal = "";
 var strconcatenate = "";
   //Main Function Start
    $(function () {

                if ($("#UserName").val()=='') //to unselect the last dynamic checkbox that create issue.
                {
                  $(".rdselectcontractdynamic").each(function (index) {
                     $(this).removeAttr('checked');
                  });
    
                }
                
                var removeSpan=$("#spnRemoveclasses");
                removeSpan.removeClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all");
                removeSpan.removeAttr('role');
                removeSpan.removeAttr('aria-expanded');
                removeSpan.removeAttr('aria-selected');
                removeSpan.removeAttr('tabindex');
     
                removeSpan.live("mouseover", function (e) {
                        $("#spnRemoveclasses").removeClass("ui-state-hover"); 
                });

      
                $('#spnRemoveclasses').attr('onclick','').unbind('click');

                //On Page Load show hide the Other Panel
                if($("#ADSLprovider option:selected").text()=="Other")
                {
                        $("#divshowhideOther").show();
                }
                else
                {
                        $("#ADSLproviderOther").val('');
                        $("#divshowhideOther").hide();
                }
         
                //TopBar 
                $("#link_Configuration").addClass("current");
                $("#link_Signup, #link_Availability, #link_Extras").addClass("completed");

                $(".Topstate li").each(function (index) {
                        if($(this).hasClass('completed'))
                        {
                        var get=$(this).attr('id');
                        if(get!=null)
                        {
                        var strhref=get.split('_')[1];
                        }
                        var strshowtext=$(this).text();
                        var makehref = hdnReplaceTextString;
                        var afterreplace= makehref.replace("ReplaceText",strhref);
                        $(this).html("<a href="+afterreplace+">"+strshowtext+"</a>");
                        }
                });

       
                 var strconcatenatcontract = "";
                //this each loop we need on page load we have define array contain how much values.
                  $(".contacttabledynamic").each(function (index) {
                             strconcatenate += "|" + ",";
                  });

                //make dynamic checkbox group by
                $(".rdselectdynamic").each(function (index) {
                            var len = $('.rdselectdynamic').length;
                            $(this).attr('name', $(this).attr('rel'));

                            //on page load select only selected checkbox
                            if ($("#strSubExtrasDetailID").val() == '') {
            
                                if (index == len - 1) {
                                    $("#strSubExtrasDetailID").val(strconcatenate);
                                }
               
                            }
                            else { //updated values from database
                                $(".rdselectdynamic").each(function (index) {
                                    if ($("#strSubExtrasDetailID").val().indexOf($(this).val()) != -1) {
                                        $(this).attr('checked', 'checked');
                                    }
                                });
                            }
                });

                 //this each loop we need on page load we have define array contain how much values.
                  $(".contactdetaildynamicfull").each(function (index) {
                          strconcatenatcontract += "|" + ",";
                  });
       
                $(".rdselectcontractdynamic").each(function (index) {
                            var lencontract = $('.rdselectcontractdynamic').length;
                            $(this).attr('name', $(this).attr('rel'));
                  
                            //on page load select only selected checkbox
                            if ($("#strExtraPlanQuotaID").val() == '') {
                                    if (index == lencontract - 1) {
                                    $("#strExtraPlanQuotaID").val(strconcatenatcontract);
                                }
                            }
                            else {
                   
                                //updated values from database
                                $(".rdselectcontractdynamic").each(function (index) {
                                    if ($("#strExtraPlanQuotaID").val().indexOf($(this).val()) != -1) {
                                        $(this).attr('checked', 'checked');
                                    }
                                });
                            }
                        });
                });
                //Main Function End
                    $(".rdselectdynamic").live("change", function (e) {
                        getplanQuotaExtras($(this).val(), $(this), $(this).attr('rel'), $(this).attr('name'));
                    var getdynamicValues = $(this).val();
                    if (getdynamicValues != '') {
                        //because array index start from zero, we will make this also start from zero.
                        var getIndex = $(this).attr('rel') - 1;
                        var getCommaSeparatedValues = $("#strSubExtrasDetailID").val();
                        var array = getCommaSeparatedValues.split(',');

                        //loop through array and replace with selected value by the user.
                        for (var i = 0; i < array.length; ++i) {
                            if (array[i] != '') {
                                if (i == getIndex) {
                                    array[i] = getdynamicValues;
                                }
                            }
                        }
                        $("#strSubExtrasDetailID").val(array);

                        //make quota value(|)  against it.
                        var getCommaSeparatedValuesQ = $("#strExtraPlanQuotaID").val();
                        var arrayQ = getCommaSeparatedValuesQ.split(',');
                        //loop through array and replace with selected value by the user.
                        for (var i = 0; i < arrayQ.length; ++i) {
                            if (arrayQ[i] != '') {
                                if (i == getIndex) {
                                    arrayQ[i] = '|';
                                }
                            }
                        }
                        $("#strExtraPlanQuotaID").val(arrayQ);

                    }
                    //need for No thanks checkbox
                    $(this).closest(".contacttabledynamic").find(".clsNothanks").removeAttr("checked");
                  
                    $(this).closest(".contacttabledynamic").find(".rdselectdynamic").each(function (index) {
                      $(this).removeClass("errorforaccordian");
                    });
                });


                $(".rdselectcontractdynamic").live("change", function (e) {
                  
                    var getdynamicValuescontract = $(this).val();

                    if (getdynamicValuescontract != '') {
                        //because array index start from zero, we will make this also start from zero.
                        var getIndexSingle = $(this).attr('rel').split('_');
                        var getIndexcontract = getIndexSingle[0] - 1;
                        var getCommaSeparatedValuescontract = $("#strExtraPlanQuotaID").val();
                        var arraycontract = getCommaSeparatedValuescontract.split(',');

                        //loop through array and replace with selected value by the user.
                        for (var i = 0; i < arraycontract.length; ++i) {
                            if (arraycontract[i] != '') {
                                if (i == getIndexcontract) {
                                    arraycontract[i] = getdynamicValuescontract;
                                }
                            }
                        }
                        $("#strExtraPlanQuotaID").val(arraycontract);
                    }
                    //need for No thanks checkbox
                    $(this).closest(".contactdetal").find(".clsNothanks").removeAttr("checked");
                    $(this).closest(".contactdetaildynamicfull").find(".rdselectcontractdynamic").each(function (index) {
                        $(this).removeClass("errorforaccordian");
                    });
                });

                 $("#ADSLprovider").live("change", function (e) {

                             if($("#ADSLprovider option:selected").text()=="Other")
                             {
                              $("#divshowhideOther").show();
                             }
                             else
                             {
                             $("#ADSLproviderOther").val('');
                             $("#divshowhideOther").hide();
                             }
                  });

          //Validation for the Existing DSL Provider Name.
          function btnclickNextSubmit()
          {
              $("#loaderCenter").show();
              $('#screen').css({ 'display': 'block', opacity: 0.3, 'width': $(document).width(), 'height': $(document).height() });
                          //blank cookies:(We don't need these 2 cookies after confirmation step.)
                           $.cookie("PlanCookie", null, { path: '/', expires: -5 });

                          //if this is blank means success.
                          var checkAllValidation='';
                          //Validation for Username start
                          var VardivErrOthertopUserName=$("#divErrOthertopUserName");
                          var VardivErrInsideUserName=$("#divErrInsideUserName");
                           if($("#UserName").val()=="")
                              {
                                VardivErrOthertopUserName.html("<ul><li>Please enter Username.</li></ul>");
                                VardivErrOthertopUserName.show();
                                VardivErrInsideUserName.html("Please enter Username.");
                                VardivErrInsideUserName.show();
                                checkAllValidation=0;
                              }
                              else
                              {
                               VardivErrOthertopUserName.html('');
                               VardivErrOthertopUserName.hide();
                               VardivErrInsideUserName.html('');
                               VardivErrInsideUserName.hide();
                              }
                              //Validation for UserName End

                              //Validation for ADSL Provider start
                              
                              var VardivErrOthertopProvider=$("#divErrOthertopProvider");
                              var VardivErrInsideADSLProvider=$("#divErrInsideADSLProvider");
                               if($("#ADSLprovider").val()=="")
                              {
                                VardivErrOthertopProvider.html("<ul><li>Please select ADSLprovider.</li></ul>");
                                VardivErrOthertopProvider.show();
                                VardivErrInsideADSLProvider.html("Please select ADSLprovider.");
                                VardivErrInsideADSLProvider.show();
                                 checkAllValidation=0;
                              }
                              else
                              {
                               VardivErrOthertopProvider.html('');
                               VardivErrOthertopProvider.hide();
                               VardivErrInsideADSLProvider.html('');
                               VardivErrInsideADSLProvider.hide();
                              }
                              //Validation for ADSL Provider End

                          // Validation for Plan Start
                          var str1=$("#strSubExtrasDetailID").val();
                          var str2="|";
                          var str1contract=$("#strExtraPlanQuotaID").val();
                        
                          //Inserting Values Will not contain (|)Zero, we fix Zeros at page load if no value in database
                          if(str1.indexOf(str2) != -1){
                          var VardivErrDynamicGrid=$("#divErrDynamicGrid");
                           VardivErrDynamicGrid.show();
                           VardivErrDynamicGrid.html("<ul><li>Please select Plan</li></ul>");
                          //for each loop for dynamic table.

                           $(".contacttabledynamic").each(function (index) {

                               var TopchkNoThanks = $(this).find(".clsNothanks");
                               //if checkbox checked no validation needed.

                               if (TopchkNoThanks.is(':checked')) {
                                   $(this).find('.divErrDynamicGridMultiple').hide();
                                   $(this).find('.divErrDynamicGridMultiple').html('');
                                   $(this).find('#item_SubExtrasDetailName').removeClass("errorforaccordian");

                               }
                               else {
                                   if ($(this).find('.rdselectdynamic').is(':checked')) {
                                       $(this).find('.divErrDynamicGridMultiple').hide();
                                       $(this).find('.divErrDynamicGridMultiple').html('');
                                       $(this).find('#item_SubExtrasDetailName').removeClass("errorforaccordian");
                                       
                                   }
                                   else {
                                       $(this).find('.divErrDynamicGridMultiple').show();
                                       $(this).find('.divErrDynamicGridMultiple').html("Please select Plan");
                                       $(this).find('#item_SubExtrasDetailName').addClass("errorforaccordian");

                                   }
                               }
                           });
             
                               checkAllValidation=0;
                          }
                         //Validation for Plan End


                         //Validation for Contract length start
                          //Inserting Values Will not contain Zero, we fix Zeros at page load if no value in database
                          if(str1contract.indexOf(str2) != -1){
                           $("#divErrDynamicContract").show();
                           $("#divErrDynamicContract").html("<ul><li>Please select Contract Length.</li></ul>");
                          //for each loop for dynamic table.
                           $(".contactdetaildynamicfull").each(function (index) {

                               var TopchkNoThanksContract = $(this).parent().find(".clsNothanks");
                               if (TopchkNoThanksContract.is(':checked')) {
                                   $(this).find('.divErrDynamicContractmultiple').hide();
                                   $(this).find('.divErrDynamicContractmultiple').html('');
                                   $(this).find('#itemcon_ExtraPlanQuotaValue').removeClass("errorforaccordian");
                               }
                               else {
                                   if ($(this).find('.rdselectcontractdynamic').is(':checked')) {

                                       $(this).find('.divErrDynamicContractmultiple').hide();
                                       $(this).find('.divErrDynamicContractmultiple').html('');
                                       $(this).find('#itemcon_ExtraPlanQuotaValue').removeClass("errorforaccordian");
                                   }
                                   else {

                                       $(this).find('.divErrDynamicContractmultiple').show();
                                       $(this).find('.divErrDynamicContractmultiple').html("Please select Contract Length");
                                       $(this).find('#itemcon_ExtraPlanQuotaValue').addClass("errorforaccordian");
                                   }
                               }
                           });
             
                  
                             checkAllValidation=0;
                          }
                         //Validatio of Contract Length End

                          //Validation for provider Other Start
                            if($("#ADSLprovider option:selected").text()=="Other")
                             {
                                  if($("#ADSLproviderOther").val()!='')
                                    {
                                     $("#divErrOther, #divErrOthertop").html('');
                                     $("#ADSLproviderOther").removeClass("errorforaccordian");
                                    }
                                   else
                                    {
                                    $("#divErrOther, #divErrOthertop").show();
                                    $("#divErrOther").html("Please enter Provider Name");
                                    $("#divErrOthertop").html("<ul><li>Please enter Provider Name</li></ul>");
                                    $("#ADSLproviderOther").addClass("errorforaccordian");
                                    $("#accordion").accordion("activate", 2);
                                   checkAllValidation=0;
                                    }
                            }
                             else
                            {
                                    $("#divErrOther, #divErrOthertop").html('');
                            }
                            //Validation for Provider Other End
                            
                            //Bundle Validation Start
                               var chkSplit=$.cookie("MainCookie");
                               if(chkSplit!=null)
                               {
                               var planSelected = $.cookie("MainCookie").split('|')[0];
                               }
                               
                             
                             if(planSelected!='')
                             {
                                 var StrBundleADSLHomephone = hdnBundleADSLHomeString;
                                 var StrBundleADSLVOIP = hdnBundleADSLVOIPString;
                                 var StrBundleADSLHomephonePlusVOIP = hdnBundleADSLPhoneVOIPString;
                                 //if cookie value match with bundle plan ID
                                 if(planSelected==StrBundleADSLHomephone || planSelected==StrBundleADSLVOIP || planSelected==StrBundleADSLHomephonePlusVOIP)
                                 {
                                           //Connection Method
                                           if($("#ConnectionMethodID").val()=="")
                                           {
                                                      
                                                        $("#divErrInsideConn, #divErrConnectionMethod").show();
                                                        $("#divErrInsideConn").html("Please select Connection Method");
                                                        $("#divErrConnectionMethod").html("<ul><li>Please select Connection Method</li></ul>");
                                                        checkAllValidation=0;
                                            }
                                             else
                                            {
                                                    $("#divErrInsideConn, #divErrConnectionMethod").html('');
                                            }
                                            //Directory Listing
                                            if($("#DirectoryListingID").val()=="")
                                            {
                                                     
                                                        $("#divErrInsideDir, #divErrDirectoryListing").show();
                                                        $("#divErrInsideDir").html("Please enter Directory Listing");
                                                        $("#divErrDirectoryListing").html("<ul><li>Please select Directory Listing</li></ul>");
                                                        checkAllValidation=0;
                                            }
                                             else
                                            {
                                                    $("#divErrInsideDir, #divErrDirectoryListing").html('');
                                            }

                                 }

                             }
                            //Bundle Validation End

                                        // Validation for Hardware Start
                                        var str1H = $("#strSubHardwareDetailID").val();
                                        var str2H = "|";
                                        //Inserting Values Will not contain (|)Zero, we fix Zeros at page load if no value in database
                                        if (str1H.indexOf(str2H) != -1) {
                                            var VardivErrDynamicGridH = $("#divErrDynamicGridH");
                                            VardivErrDynamicGridH.show();
                                            VardivErrDynamicGridH.html("<ul><li>Please select Hardware</li></ul>");
                                            //for each loop for dynamic table.

                                            $(".contacttabledynamicH").each(function (index) {

                                                var TopchkNoThanksH = $(this).find(".clsNothanksH");
                                                //if checkbox checked no validation needed.
                                                
                                                if (TopchkNoThanksH.is(':checked')) {
                                                    $(this).find('.divErrDynamicGridMultipleH').hide();
                                                    $(this).find('.divErrDynamicGridMultipleH').html('');
                                                    $(this).find('#items_SubHardwareDetailID').removeClass("errorforaccordian");
                                                }
                                                else {
                                                    if ($(this).find('.rdselectdynamicH').val() > 0) {
                                                        $(this).find('.divErrDynamicGridMultipleH').hide();
                                                        $(this).find('.divErrDynamicGridMultipleH').html('');
                                                        $(this).find('#items_SubHardwareDetailID').removeClass("errorforaccordian");

                                                    }
                                                    else {
                                                        $(this).find('.divErrDynamicGridMultipleH').show();
                                                        $(this).find('.divErrDynamicGridMultipleH').html("Please select Hardware");
                                                        $(this).find('#items_SubHardwareDetailID').addClass("errorforaccordian");

                                                    }
                                                }
                                            });

                                            checkAllValidation = 0;
                                        }
                                        //Validation for Hardware End



                            //Final Result Start
                            if(checkAllValidation=="0")
                            {
                                $("#loaderCenter").hide();
                                $('#screen').css({ 'display': 'none' });
                                 return false;
                            }
                            else
                            {
                                $("#loaderCenter").show();
                                $('#screen').css({ 'display': 'block', opacity: 0.3, 'width': $(document).width(), 'height': $(document).height() });
                                 $("#divErrOther, #divErrOthertop").html('');
                                 $("#divErrOther, #divErrOthertop").hide();

                                 $(".contacttabledynamic").each(function (index) {
                                      $(this).find('.divErrDynamicGridMultiple').hide();
                                      $(this).find('.divErrDynamicGridMultiple').html('');
                                  });

                                  $(".contacttabledynamicH").each(function (index) {
                                      $(this).find('.divErrDynamicGridMultipleH').hide();
                                      $(this).find('.divErrDynamicGridMultipleH').html('');
                                  });
           
                                 $(".contactdetaildynamicfull").each(function (index) {
                                      $(this).find('.divErrDynamicContractmultiple').hide();
                                      $(this).find('.divErrDynamicContractmultiple').html('');
                                 });

                                  return true;  
                                 
                            }
                             //Final Result End
          
          }

          $("#mySignupConfigForm").submit(function (e) {
                      if ($(this).valid()) {
                          $("#loaderCenter").show();
                          $('#screen').css({ 'display': 'block', opacity: 0.3, 'width': $(document).width(), 'height': $(document).height() });
                      }
          });

           $("#btnback").live("click", function (e) {
               $("#loaderCenter").show();
               $('#screen').css({ 'display': 'block', opacity: 0.3, 'width': $(document).width(), 'height': $(document).height() });
               });

        $(function () {

            if ($.cookie("MainCookie") != null) {
                var chkName = $.cookie("MainCookie").split('|')[2];
                var n = chkName.indexOf(hdnNakedString);
                var n1 = chkName.indexOf(hdnBundleString);
                if (n != -1 || n1 != -1) {
                    $('#ServicePhoneNumber').rules('remove', 'required');
                         
                }

            }
        });

        //region-Start code of No thanks
        $(function () {
            if ($("#ADSLprovider").val() == "") { }
            else { //means Update case
                $(".contacttabledynamic").each(function (index) {
                    var testchecked = "";
                    $(this).find(".rdselectdynamic").each(function (index) {
                        if ($(this).is(':checked')) {
                            testchecked = 1;
                        }
                    });
                    if (testchecked == "") {
                        $(this).find(".clsNothanks").attr("checked", "checked");
                    }
                });

                $(".contacttabledynamicH").each(function (index) {
                    var testcheckedH = "";
                    $(this).find(".rdselectdynamicH").each(function (index) {
                        if ($(this).val()!=0) {
                            testcheckedH = 1;
                        }
                    });
                    if (testcheckedH == "") {
                        $(this).find(".clsNothanksH").attr("checked", "checked");
                    }
                });
            }
        });

        //Code for "No thanks checkbox"
        $('.clsNothanks').live('click', function () {

            if ($(this).is(':checked')) {
                // start Removed the checked from the plans and contracts
                var TopdivPlans = $(this).closest(".contacttabledynamic");
                var TopdivPlansContract = $(this).closest(".contactdetal");

                TopdivPlans.find(".countforPlans").each(function (i) {
                    $(this).find(".rdselectdynamic").removeAttr("checked");
                    $(this).find(".rdselectdynamic").removeClass("errorforaccordian");
                });
                TopdivPlans.find(".divErrDynamicGridMultiple").hide();


                TopdivPlansContract.find(".rdselectcontractdynamic").each(function (i) {
                    $(this).removeAttr("checked");
                    $(this).removeClass("errorforaccordian");
                });
                TopdivPlansContract.find(".divErrDynamicContractmultiple").hide();
                // End Removed the checked from the plans and contracts

                funCommonNoThanks(TopdivPlans, TopdivPlansContract, 0);

            }
            else {
                var TopdivPlans = $(this).closest(".contacttabledynamic");
                var TopdivPlansContract = $(this).closest(".contactdetal");
                funCommonNoThanks(TopdivPlans, TopdivPlansContract, '|');
            }
        });

        function funCommonNoThanks(TopdivPlansV, TopdivPlansContractV, valuePass) {

            //because array index start from zero, we will make this also start from zero.
            var getrdselectdynamic = TopdivPlansV.find(".rdselectdynamic").attr("rel");
            var getIndex1 = getrdselectdynamic - 1;
            var getCommaSeparatedValues1 = $("#strSubExtrasDetailID").val();
            var array1 = getCommaSeparatedValues1.split(',');

            //loop through array and replace with selected value by the user.
            for (var i = 0; i < array1.length; ++i) {
                if (array1[i] != '') {
                    if (i == getIndex1) {
                        array1[i] = valuePass;
                    }
                }
            }
            $("#strSubExtrasDetailID").val(array1);
            //End replace the array value with zero

            //start Contract Length replace the array value with zero
            //because array index start from zero, we will make this also start from zero.

            var getrdselectcontractdynamic = TopdivPlansContractV.find(".rdselectcontractdynamic").attr("rel");

            var getIndexSingle1 = getrdselectcontractdynamic.split('_');
            var getIndexcontract1 = getIndexSingle1[0] - 1;
            var getCommaSeparatedValuescontract1 = $("#strExtraPlanQuotaID").val();
            var arraycontract1 = getCommaSeparatedValuescontract1.split(',');

            //loop through array and replace with selected value by the user.
            for (var i = 0; i < arraycontract1.length; ++i) {
                if (arraycontract1[i] != '') {
                    if (i == getIndexcontract1) {
                        arraycontract1[i] = valuePass;
                    }
                }
            }
            $("#strExtraPlanQuotaID").val(arraycontract1);
            //End replace the array value with zero
        }
        //region-End code of No thanks


        //#regioon for Hardware
        //Code for "Hardware No thanks checkbox"
        $('.clsNothanksH').live('click', function () {
            if ($(this).is(':checked')) {
                var TopdivPlans = $(this).closest(".contacttabledynamicH");
                TopdivPlans.find(".countforPlansH").each(function (i) {
                    $(this).find(".rdselectdynamicH").val(0);
                    $(this).removeClass("errorforaccordian");
                });
                TopdivPlans.find(".divErrDynamicGridMultipleH").hide();
                funCommonNoThanksH(TopdivPlans, 0);
            }
            else {
                var TopdivPlans = $(this).closest(".contacttabledynamicH");
                funCommonNoThanksH(TopdivPlans, '|');
            }


        });

        $('.rdselectdynamicH').live('change', function () {

            //loop of all Qty boxes of the selected box
            var TopParent = $(this).closest(".contacttabledynamicH");
            getFinal = "";
            TopParent.find(".rdselectdynamicH").each(function (index) {
                var getdynamicValuesQtyH = $(this).val();
                if (getdynamicValuesQtyH == 0) { }
                else {
                    var getdynamicValuesHH = $(this).closest(".countforPlansH").attr("id");
                    getFinal = getFinal + (getdynamicValuesHH + "&" + getdynamicValuesQtyH + "#");
                }

            });
            if (getFinal == "") {
                getFinal="|#"
            }

            //because array index start from zero, we will make this also start from zero.
            var getIndex = $(this).attr('rel1') - 1;
            var getCommaSeparatedValues = $("#strSubHardwareDetailID").val();
            var array = getCommaSeparatedValues.split(',');

            //loop through array and replace with selected value by the user.
            for (var i = 0; i < array.length; ++i) {
                if (array[i] != '') {
                    if (i == getIndex) {
                        array[i] = getFinal.slice(0, -1);
                    }
                }
            }
            $("#strSubHardwareDetailID").val(array);

            if ($(this).val() == "0") { }
            else {
                //need for No thanks checkbox
                $(this).closest(".contacttabledynamicH").find(".clsNothanksH").removeAttr("checked");
            }

        });
       
        var strconcatenateH = "";
        $(".contacttabledynamicH").each(function (index) {
            strconcatenateH += "|" + ",";
        });

        //make dynamic checkbox group by
        $(".rdselectdynamicH").each(function (index) {
            var len = $('.rdselectdynamicH').length;
            $(this).attr('name', $(this).attr('rel'));

            //on page load select only selected checkbox
            if ($("#strSubHardwareDetailID").val() == '') {
                if (index == len - 1) {
                    $("#strSubHardwareDetailID").val(strconcatenateH);
                }
            }
            else { //updated values from database
                $(".rdselectdynamicH").each(function (index) {

                    var splitstrSubHardwareDetailID = $("#strSubHardwareDetailID").val().split(",");
                    var closestValue = $(this).closest('.countforPlansH').attr('id');
                    var i;
                    var j;
                    for (i = 0; i < splitstrSubHardwareDetailID.length; ++i) {
                        var splitHash = splitstrSubHardwareDetailID[i].split("#");

                        for (j = 0; j < splitHash.length; ++j) {
                            var splitAND = splitHash[j].split("&");
                            var SHID = splitAND[0];
                            var SHQty = splitAND[1];
                            if (closestValue == SHID) {
                                $(this).val(SHQty);
                            }

                        }
                    }
                     
                });

            }
        });

        function funCommonNoThanksH(TopdivPlansH, valuePassH) {

            //because array index start from zero, we will make this also start from zero.
            var getrdselectdynamic = TopdivPlansH.find(".rdselectdynamicH").attr("rel1");
            var getIndexH = getrdselectdynamic-1;
            var getCommaSeparatedValuesH = $("#strSubHardwareDetailID").val();
            var arrayH = getCommaSeparatedValuesH.split(',');
           
            //loop through array and replace with selected value by the user.
            for (var i = 0; i < arrayH.length; ++i) {
                if (arrayH[i] != '') {
                    if (i == getIndexH) {
                        arrayH[i] = valuePassH;
                   }
                }
            }
            $("#strSubHardwareDetailID").val(arrayH);
            //End replace the array value with zero
         }
        //#endregion